<template>
    <div class='search'>
        <div class="searchBox">
            <input type="text" v-model="searchValue" placeholder="请输入您要搜索的菜名">
            <div class="imgBox" @click="getList"><img :src="searchButton" alt=""></div>
        </div>
        <div class="list">
            <ul>
                <li class="m_item" @click="goInfo(item._id,item.img)" v-for="item in menuList" :key="item._id">
                    <div class="item_img">
                        <img :src="item.img" alt="">
                    </div>
                    <div class="item_p">
                        {{ item.name }}
                    </div>
                </li>
            </ul>
        </div>
    </div>
    
</template>

<script>

import searchButton from '../../images/search.png'
import { getMenuList } from '../../server/getData.js'
export default {
    data(){
        return {
            searchButton,
            searchValue:'',
            menuList:[]
        }
    },
    methods:{
        getList(){
            let parmas = {
                name:this.searchValue,
                type:'',
                isRandom:'false'
            }
            getMenuList(parmas,res=>{
                console.log(res.list)
                this.menuList = res.list
            })
        },
        goInfo(id,img){
            var url = "../menuInfo/main?id=" + id + '&img=' +img
            wx.navigateTo({url})
        },
    },
    mounted() {
        // this.getList()
    },
}
</script>
<style >
.searchBox{
    display: flex;
    justify-content: space-around;
}
.searchBox input{
    border: 1px solid #ddd;
    width: 75%;
    height: 30px;
    line-height: 30px;
    padding-left: 10px;
    font-size: 16px;
}
.imgBox img {
    width: 30px;
    height: 30px;
    margin-right: 10px;
}
.search .list {
    padding-top: 50px;
}
.m_item{
    display: flex;
    padding: 10px 5%;
    border-bottom: 1px solid #ccc;
}
.m_item .item_img{
    flex:2;
}
.m_item .item_p{
    flex:3;
    padding: 0 5%;
}
.m_item .item_img img{
    width: 150px;
    height: 100px;
}
</style>